<!DOCTYPE html>
<html>
{include file='public/header'}
<body>
{include file='public/x-nav'}
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so layui-form-pane">
            <input class="layui-input" placeholder="分类名" name="cate_name">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon"></i>搜索</button>
        </form>
    </div>
    <!--<blockquote class="layui-elem-quote">每个tr 上有两个属性 cate-id='1' 当前分类id fid='0' 父级id ,顶级分类为 0，有子分类的前面加收缩图标<i
            class="layui-icon x-show" status='true'>&#xe623;</i></blockquote>-->
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加分类','add',900,650)"><i class="layui-icon"></i>添加分类
        </button>
        <span class="x-right" style="line-height:40px">共有数据：{:count($list)}条</span>
    </xblock>
    <table class="layui-table layui-form">
        <thead>
        <tr>
            <th>ID</th>
            <th>分类名</th>
            <th>排序</th>
            <th>操作</th>
        </thead>
        <tbody class="x-cate">
        {volist name='list' id='item'}
        <tr cate-id="{$item['id']}" fid="{$item['pid']}">
            <td>{$item['id']}</td>
            <td>
                {if $item['_level']!=1}
                {:str_repeat('&nbsp;',$item['_level']*4)}
                {/if}
                {if $item['has_child']}
                <i class="layui-icon x-show" status='true'>&#xe623;</i>
                {/if}
                {$item['_name']}
            </td>
            <td>{$item['sort']}</td>
            <td class="td-manage">
                <button class="layui-btn layui-btn layui-btn-xs" onclick="x_admin_show('编辑','edit/id/{$item["id"]}')"><i
                        class="layui-icon">&#xe642;</i>编辑
                </button>
                {if $item['_level']<3}
                <button class="layui-btn layui-btn-warm layui-btn-xs" onclick="x_admin_show('添加子栏目','add/pid/{$item["id"]}')"><i
                        class="layui-icon">&#xe642;</i>添加子栏目
                </button>
                {/if}
                <button class="layui-btn-danger layui-btn layui-btn-xs" onclick="del(this,'{$item["id"]}')"
                        href="javascript:;"><i class="layui-icon">&#xe640;</i>删除
                </button>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
</div>
<style type="text/css">

</style>
<script>
    layui.use(['form'], function () {
        form = layui.form;

    });
    /*用户-删除*/
    function del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $.post("{:url('delete')}",{id:id},function(response){
                if(response.code === 200){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!', {icon: 1, time: 1000});
                }else{
                    layer.msg(response.msg, {icon: 5, time: 1000});
                }
            },'json');
        });
    }
</script>
</body>

</html>